package com.example.demo.service.Student;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.demo.entity.Student;
import com.example.demo.mapper.StudentMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service("StudentService")
public class StudentServiceImpl implements StudentService {
    @Resource
    private StudentMapper studentMapper;

    @Override
    public List<Student> queryStudentList(){
        return studentMapper.selectList(null);
    }

    @Override
    public List<Student> queryStudentById(int id){
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return studentMapper.selectList(queryWrapper);
    }

    @Override
    public void addStudent(Student student){
        studentMapper.insert(student);
    }

    @Override
    public void deleteStudent(int id) {
        studentMapper.deleteById(id);
    }

    @Override
    public void updateStudent(Student student){
        studentMapper.updateById(student);
    }

    @Override
    public  List<Student> queryStudentByName(String name){
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("name",name);
        return studentMapper.selectList(queryWrapper);
    }

    @Override
    public  List<Student> queryStudentByMajor(String major){
        QueryWrapper<Student> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("major",major);
        return studentMapper.selectList(queryWrapper);
    }

}
